package topday1_9.demo4;

/**
 * @Auther:小陈的Java
 * 重写equals方法
 */
//1.重写equals方法
public class Demo11 {
    public static void main(String[] args) {

        User user = new User(1,"小红");
        User user2 = new User(1,"小红");
        System.out.println(user.equals(user2));

    }
}
class User1{
    private int id;
    private String name;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public User1(int id, String name) {
        this.id = id;
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public User1() {
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof User) {
            User uu = (User)obj;
            return this.id==uu.getId() && this.name.equals(uu.getName());
        }
        return false;
    }
}
